package xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.model;

import android.os.Handler;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import xixirupan.tmgp.tencent.com.vmeim.config.URLConfig;
import xixirupan.tmgp.tencent.com.vmeim.retrofit.ICategoryR;

/**
 * Created by lenovo on 2016/10/19.
 */

public class CategoryBiz implements ICatgory {
    public List<Object> lists =new ArrayList<>();
    private Handler handler =new Handler();
    GetDataListListener getDataList;
    public CategoryBiz ()
    {
       // this.getDataList =getDataList;
    }
    @Override
    public void getData(final GetDataListListener getDataList) {
        this.getDataList = getDataList;

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(URLConfig.Url.BASE_URL)
                //对数据进行解析解析成实体类
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        //创建网络连接的接口对象
        ICategoryR iCategoryR = retrofit.create(ICategoryR.class);
        Call<CategoryBean> call = iCategoryR.category();
        call.enqueue(new Callback<CategoryBean>() {
            @Override
            public void onResponse(Call<CategoryBean> call, Response<CategoryBean> response) {
                DataBean data = response.body().getData();
                List<CategoriesBean> categories = data.getCategories();
                for (int i = 0; i < categories.size(); i++) {
                    String name = categories.get(i).getName();
                    lists.add(name);
                    List<SubChildrenBean> subChildren = categories.get(i).getSubChildren();
                    lists.add(subChildren);
                }
                getDataList.getDataListener(lists);

            }

            @Override
            public void onFailure(Call<CategoryBean> call, Throwable t) {

            }
        });
    }

   public  interface  GetDataListListener
    {
        void getDataListener(List<Object> lists);
    }

}
